﻿using System;
using System.Windows.Forms;
using System.ServiceProcess;


namespace EasyWindowsServiceManager.Forms
{
    public partial class ListServices : Form
    {
        #region Propiedades
        /// <summary>
        /// Name of machine to connect
        /// </summary>
        public String machineName { get; set; }
        #endregion

        #region Constructors
        public ListServices(String MachineName)
        {
            this.machineName = MachineName;
            InitializeComponent();
        }

        private ServiceController[] servicios;
        private ServiceController servicio;


        #endregion





        public ListServices()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }


        protected void showServices() {
            servicios = ServiceController.GetServices(this.machineName);
            foreach (var item in servicios)
            {
                ListViewItem lvi = this.listView1.Items.Add(item.ServiceName);
                lvi.SubItems.Add(item.Status.ToString());
                lvi.SubItems.Add(item.DisplayName);
                lvi.SubItems.Add(item.ServiceType.ToString());



            }
        
        
        }

        private void ListServices_Load(object sender, EventArgs e)
        {
            listView1.View = View.Details;
            listView1.FullRowSelect = true;
            listView1.GridLines = true;
            listView1.LabelEdit = false;
            listView1.HideSelection = false;
            listView1.Columns.Clear();
            listView1.Columns.Add("Servicio", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("Estado", 60, HorizontalAlignment.Left);
            listView1.Columns.Add("Descripción", 200, HorizontalAlignment.Left);
            listView1.Columns.Add("Tipo de servicio", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("Equipo", 70, HorizontalAlignment.Left);
            this.showServices();
        }


    }
}
